package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.base.BaseMapper;
import com.atguigu.base.BaseService;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.entity.Community;
import com.atguigu.entity.House;
import com.atguigu.mapper.CommunityMapper;
import com.atguigu.mapper.HouseMapper;
import com.atguigu.service.CommunityService;
import com.atguigu.util.CastUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import sun.dc.pr.PRError;

import java.util.List;
import java.util.Map;

/**
 * @Author: 翟文海
 * @Date: 2022/10/28/028 19:49
 * @Version: 1.0
 * @Description: TODO
 **/
@Service(interfaceClass = CommunityService.class)
public class CommunityServiceImpl extends BaseServiceImpl<Community> implements CommunityService {

    @Autowired
    private CommunityMapper communityMapper;
    @Autowired
    private HouseMapper houseMapper;

    @Override
    protected BaseMapper<Community> getMapper() {
        return communityMapper;
    }

    @Override
    public void delete(Long id) {
        List<House> houseList = houseMapper.getByCommunityId(id);
        if (!CollectionUtils.isEmpty(houseList)) {
            throw new RuntimeException("此小区还有相关的房源在售，不能删除！");
        }
        //可以删
        super.delete(id);
    }

}
